package thread1;

import java.util.concurrent.Callable;

/**
 * @classname:BalanceAccount
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/19 15:09
 * @version: 0.1
 * @since:1.8
 */
public class BalanceAccountCal implements Callable<Integer> {
    private Integer money;
    private Integer balance =1000;
    private boolean flag;

    @Override
    public Integer call() throws Exception {
        if(flag){
            balance+=money;
            System.out.println(Thread.currentThread().getName()+"向我转账"+money+"元，余额"+balance);
        }else {
            balance-=money;

            System.out.println("我向"+Thread.currentThread().getName()+"转账"+money+"元，余额"+balance);
        }
        return balance;
    }

    public BalanceAccountCal(Integer money, boolean flag) {
        this.money = money;
        this.flag = flag;
    }

    public Integer getBalance() {
        return balance;
    }
}
